﻿<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="util.JdbcUtil" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="bean.SupplierBean" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
  <head>
    <title>supplier</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link href="resources/css/axure_rp_page.css" type="text/css" rel="stylesheet"/>
    <link href="data/styles.css" type="text/css" rel="stylesheet"/>
    <link href="files/supplier/styles.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="layui/css/laytable.css">
    <script src="resources/scripts/jquery-3.2.1.min.js"></script>
    <script src="resources/scripts/axure/axQuery.js"></script>
    <script src="resources/scripts/axure/globals.js"></script>
    <script src="resources/scripts/axutils.js"></script>
    <script src="resources/scripts/axure/annotation.js"></script>
    <script src="resources/scripts/axure/axQuery.std.js"></script>
    <script src="resources/scripts/axure/doc.js"></script>
    <script src="resources/scripts/messagecenter.js"></script>
    <script src="resources/scripts/axure/events.js"></script>
    <script src="resources/scripts/axure/recording.js"></script>
    <script src="resources/scripts/axure/action.js"></script>
    <script src="resources/scripts/axure/expr.js"></script>
    <script src="resources/scripts/axure/geometry.js"></script>
    <script src="resources/scripts/axure/flyout.js"></script>
    <script src="resources/scripts/axure/model.js"></script>
    <script src="resources/scripts/axure/repeater.js"></script>
    <script src="resources/scripts/axure/sto.js"></script>
    <script src="resources/scripts/axure/utils.temp.js"></script>
    <script src="resources/scripts/axure/variables.js"></script>
    <script src="resources/scripts/axure/drag.js"></script>
    <script src="resources/scripts/axure/move.js"></script>
    <script src="resources/scripts/axure/visibility.js"></script>
    <script src="resources/scripts/axure/style.js"></script>
    <script src="resources/scripts/axure/adaptive.js"></script>
    <script src="resources/scripts/axure/tree.js"></script>
    <script src="resources/scripts/axure/init.temp.js"></script>
    <script src="resources/scripts/axure/legacy.js"></script>
    <script src="resources/scripts/axure/viewer.js"></script>
    <script src="resources/scripts/axure/math.js"></script>
    <script src="resources/scripts/axure/jquery.nicescroll.min.js"></script>
    <script src="data/document.js"></script>
    <script src="files/supplier/data.js"></script>
    <script type="text/javascript">
      $axure.utils.getTransparentGifPath = function() { return 'resources/images/transparent.gif'; };
      $axure.utils.getOtherPath = function() { return 'resources/Other.html'; };
      $axure.utils.getReloadPath = function() { return 'resources/reload.html'; };
    </script>
        <script src="${pageContext.request.contextPath }/js/jquery.js"></script>
    <script >
      function add(sid){
        location.href="supplieradd.jsp";
      }

      function modify(sid){
        var falg= confirm("确认修改吗？？？");
        if(falg){
          location.href="suppliermodify?sid="+sid;
        }
      }
      function del(sid){
        var falg= confirm("确认删除吗？？？");
        if(falg){
          location.href="supplierdelete?sid="+sid;
        }
      }
      function hunt(){
        var sid = $("#u173_input").val();
        var name = $("#u182_input").val();
        if (name == null) {
          location.href = "supplierhunt?sid=" + sid;
        } else if (sid == null) {
          location.href = "supplierhunt?name=" + name;
        } else {
          location.href = "supplierhunt?sid=" + sid;
        }
      }
    </script>
    <style>
      .cont{
        position: relative;
      }
      #u172_div{
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        padding-top: 40px;
      }
      #sid,#name{
        width:200px;
        height: 30px;
      }
      #sub{
        width: 70px;
        height: 30px;
        background-color:rgba(0, 121, 254, 0.5);
        border-radius:3px;
        border-width:0px;
        font-family:'微软雅黑', sans-serif;
        font-weight:400;
        font-style:normal;
        font-size:14px;
        color:#FFFFFF;
        line-height:20px;
      }
      .table_huowu{
        position: absolute;
        top: 120px;
        left: 50px;
      }
      .table_huowu table{
        border-collapse:collapse;
        width: 800px;
      }
      td{
        white-space: nowrap;
      }
    </style>

    <%
      String sql ="SELECT * FROM supplier";
      try {
        PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
        ResultSet set = ps.executeQuery();
        ArrayList<SupplierBean> arr = new ArrayList<SupplierBean>();
        while (set.next()){
          SupplierBean su = new SupplierBean();
          su.setSid(set.getInt(1));
          su.setName(set.getString(2));
          su.setPerson(set.getString(3));
          su.setTel(set.getString(4));
          su.setEmail(set.getString(5));
          su.setAddress(set.getString(6));
          arr.add(su);
        }
        session.setAttribute("arr", arr);

      } catch (Exception e) {
        e.printStackTrace();
      }
    %>
  </head>
  <body>
    <div id="base" class="">

      <!-- Unnamed (矩形) -->
      <div id="u170" class="ax_default box_1">
        <div id="u170_div" class="cont">
          <div class="table_huowu">
            <table class="layui-table">
              <thead>
              <tr>
                <th>供应商id</th>
                <th>供应商名称</th>
                <th>负责人</th>
                <th>联系电话</th>
                <th>电子邮件</th>
                <th>地址</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody id="tbody">
              <c:forEach items="${arr}" var="su">
                <tr>
                  <td>${su.sid}</td>
                  <td>${su.name}</td>
                  <td>${su.person}</td>
                  <td>${su.tel}</td>
                  <td>${su.email}</td>
                  <td>${su.address}</td>
                  <td>
                    <input type="button" value="删除" onclick="del(${su.sid })" />
                    <input type="button" value="修改" onclick="modify(${su.sid })" />
                  </td>
                </tr>
              </c:forEach>
              </tbody>
            </table>
          </div>
        </div>
        <div id="u170_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u171" class="ax_default _文本段落">
        <div id="u171_div" class=""></div>
        <div id="u171_text" class="text ">
          <p><span>供应商信息管理</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u172" class="ax_default box_1">
        <div id="u172_div" class="">
          <input id="sid" placeholder="供应商ID" type="text"/>
          <input type="text" id="name" placeholder="供应商名称"/>
          <input type="submit" id="sub" value="筛选" onclick="seek()">
        </div>
        <div id="u172_text" class="text " style="display:none; visibility: hidden">
          <p></p >
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u176" class="ax_default box_1">
        <div id="u176_div" class=""></div>
        <div id="u176_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (图片 ) -->
      <div id="u177" class="ax_default _图片_">
        <img id="u177_img" class="img " src="images/customer/u149.png"  alt=""/>
        <div id="u177_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u178" class="ax_default label">
        <div id="u178_div" class=""></div>
        <div id="u178_text" class="text ">
          <p><span>筛选</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u179" class="ax_default box_1">
        <div id="u179_div" class=""></div>
        <div id="u179_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (SVG) -->
      <div id="u180" class="ax_default _图片_">
        <img id="u180_img" class="img " src="images/customer/u152.svg" alt="">
        <div id="u180_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u181" class="ax_default label">
        <div id="u181_div" class=""></div>
        <div id="u181_text" class="text ">
          <p><span>列表</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u183" class="ax_default button">
        <div id="u183_div" class=""></div>
        <div id="u183_text" class="text ">
          <p><span onclick="add(${su.sid})">添加</span></p>
        </div>
      </div>
    </div>

    <script src="resources/scripts/axure/ios.js"></script>
    <script type="text/javascript">
      function seek() {
        var sid = $("#sid").val();
        var name = $("#name").val() ;

        if (sid==null &&name==null){
          location.href="supplier.jsp";
        }
        $.ajax({
          url : "supplierhunt?sid="+sid+"&name="+name,//提交地址
          type : "post",//提交方式（get,post）
          dataType : "json",//指定服务器返回的数据类型
          success : function(data) {//请求成功后的回调函数
            console.log(data);
            $("#tbody").empty(); //删除匹配的元素集合中所有的子节点（就是不重复执行）
            var trStr = "";
            for (var i = 0; i < data.length; i++) {
              trStr += "<tr><td>" + data[i].sid +
                      "</td><td>" + data[i].name +
                      "</td><td>" + data[i].person +
                      "</td><td>" + data[i].tel +
                      "</td><td>" + data[i].address +
                      "</td><td>" + data[i].email +
                      "</td><td>" + " <input type='button' value='删除' onclick='del(${su.sid })' />"
                      +"<input type='button' value='修改' onclick='modify(${su.sid })' />"+
                      "</td></tr>"
            }
            $("#tbody").show().append(trStr);//向<tbody>内部追加内容
          },
          error : function() {
            alert('请求失败');
          }
        });
      };
    </script>
  </body>
</html>
